package com.duan.listviewdemo1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private List<Friend> friendList = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initFriends();
        FriendAdapter adapter = new FriendAdapter(MainActivity.this,
                R.layout.friend_item,friendList);
        ListView listView = (ListView) findViewById(R.id.list_view);
        listView.setAdapter(adapter);
    }

    private void initFriends(){
        for (int i = 0;i < 2;i++){
            Friend friend1 = new Friend("Friend1",R.drawable.boy1);
            friendList.add(friend1);
            Friend friend2 = new Friend("Friend2",R.drawable.man1);
            friendList.add(friend2);
            Friend friend3 = new Friend("Friend3",R.drawable.man2);
            friendList.add(friend3);
            Friend friend4 = new Friend("Friend4",R.drawable.man3);
            friendList.add(friend4);
            Friend friend5 = new Friend("Friend5",R.drawable.man4);
            friendList.add(friend5);
            Friend friend6 = new Friend("Friend6",R.drawable.man5);
            friendList.add(friend6);
            Friend friend7 = new Friend("Friend7",R.drawable.man6);
            friendList.add(friend7);
            Friend friend8 = new Friend("Friend8",R.drawable.woman1);
            friendList.add(friend8);
            Friend friend9 = new Friend("Friend9",R.drawable.woman2);
            friendList.add(friend9);
            Friend friend10 = new Friend("Friend10",R.drawable.woman3);
            friendList.add(friend10);
        }
    }
}
